package com.chaoyi.service.Impl;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.Part;

import org.springframework.stereotype.Service;

import com.chaoyi.config.WSUploadConfig;
import com.chaoyi.dao.mysql.BarrageAndUserMapper;
import com.chaoyi.model.BarrageAndUser;
import com.chaoyi.service.BarrageAndUserService;
import com.chaoyi.util.UUIDUtil;
import com.chaoyi.util.oss.ApkOSSConfigure;
import com.chaoyi.util.oss.ApkOSSManageUtil;
import com.chaoyi.util.qiniu.UploadFileQiNiu;

@Service
public class BarrageAndUserServiceImpl implements BarrageAndUserService {
	@Resource
	BarrageAndUserMapper barrageAndUserMapper;

	@Override
	public List<BarrageAndUser> findList(String offset, String limit) {
		return barrageAndUserMapper.findList(offset, limit);
	}

	@Override
	public int saveBarrageAndUser(BarrageAndUser barrageAndUser) {
		return barrageAndUserMapper.saveBarrageAndUser(barrageAndUser);
	}
	
	@Override
	public String uploadClassifyImg2WSCDN(Part uploadFile) throws IOException, Exception {
		String exten = uploadFile.getSubmittedFileName().substring(uploadFile.getSubmittedFileName().lastIndexOf("."));
		String fileName = UUIDUtil.getUUID() + exten;
//		return ApkOSSManageUtil.uploadFile(new ApkOSSConfigure(), uploadFile, WSUploadConfig.barrageUserImgPath,
//				fileName);
		return UploadFileQiNiu.uploadFile(uploadFile, WSUploadConfig.barrageUserImgPath, fileName);
	}

	@Override
	public BarrageAndUser findBarrageAndUserOne(int id) {
		return barrageAndUserMapper.findBarrageAndUserOne(id);
	}

	@Override
	public int alertBarrageAndUserSave(BarrageAndUser barrageAndUser) {
		return barrageAndUserMapper.alertBarrageAndUserSave(barrageAndUser);
	}

	@Override
	public int deleteBarrageAndUser(int id) {
		return barrageAndUserMapper.deleteBarrageAndUser(id);
	}

	@Override
	public int findCount() {
		return barrageAndUserMapper.findCount();
	}

}
